
Array.prototype.remove = function(val){
	
	var index = this.indexOf(val);
	
	if(index > -1){
		
		this.splice(index,1);
	}
}

/*设置上部导航的点击效果*/
$("li:has(.zc-hd)").css({"padding-right":22});

	$("li:has(.zc-hd)").mouseover(function(){
		
		$(this).css({"background":"white"});
		
		$(this).children("div").stop().slideDown();
		
	}).mouseout(function(){
		
		$(this).css({"background":""});
		$(this).children("div").stop().slideUp();
		
});


/**************************登录检测*************************/
var uSpan = document.getElementById("zc-login");
var aSpan = document.getElementById("zc-register");

if(getCookie("user")){
	
	var obj = getCookie("user");
	uSpan.innerHTML = "您好，"+"<a href='#'>"+obj.name+"</a>";
	aSpan.innerHTML = "<a id='log-out' class='log-out'>退出</a>"
	
	var oSpan = document.getElementById("log-out");
	oSpan.onclick = function(){
		
		//清除登录数据，刷新当前页面
		setCookie("user",null,0);
		
		window.location.href = "login.html";
	}
}


if(getCookie("cartList")){
		
	var ary = Array.from(getCookie("cartList").list);
	
		
	$("#shop-cart-num").html("购物车"+ary.length+"件");
	
	$("#cart-num").html("("+ary.length+"/30"+")")
	
	ary.forEach(function(item,lap){
		
		var tr = document.createElement("tr");
		tbody1.appendChild(tr);
		tr.id = "tr"+lap;
		
		var td1 = document.createElement("td");
		td1.className = "clearfix";
		tr.appendChild(td1);
		
		var tDiv = document.createElement("div");
		td1.appendChild(tDiv);
		tDiv.className = "tDiv clearfix";
		
		/***************店铺**************/
		var nDiv = document.createElement("div");
		tDiv.appendChild(nDiv);
		nDiv.className = "shopname";
		
		var rInput = document.createElement("input");
		nDiv.appendChild(rInput);
		rInput.type = "radio";
		rInput.name = "merchR"
		
		var tSpan = document.createElement("span");
		nDiv.appendChild(tSpan);
		tSpan.innerHTML = "店铺 ："+"<a href='http://www.zol.com/shop_194111/'>"+item.store+"</a>"
		
		/***********qq图标***********/
		var qDiv = document.createElement("div");
		qDiv.className = "contact";
		tDiv.appendChild(qDiv);
		
		var qA = document.createElement("a");
		qA.className = "tag-security";
		qDiv.appendChild(qA);
		
		
		/******************信息内容*******************/
		var dDiv = document.createElement("div");
		td1.appendChild(dDiv);
		dDiv.className = "dDiv clearfix";
		
		var inDiv = document.createElement("div");
		inDiv.className = "s-infor clearfix";
		dDiv.appendChild(inDiv);
		
		var cInput = document.createElement("input");
		inDiv.appendChild(cInput);
		cInput.type = "checkbox";
		cInput.name = "cart-id";
		
		var pImg = document.createElement("img");
		inDiv.appendChild(pImg);
		pImg.src = "../images/proImg.jpg";
		
		
		var delDiv = document.createElement("div");
		dDiv.appendChild(delDiv);
		delDiv.className = "delDiv";
		
		var delA = document.createElement("a");
		delDiv.appendChild(delA);
		delA.className = "delA";
		delA.idNum = lap;
		delA.innerHTML = "删除";
		
		
		delA.onclick = function(){
			
			tbody1.removeChild(tr);
			
			ary.remove(item);
			
			setCookie("cartList",{"list":ary},7);
			
			history.go(0);
		}
		
	});
		
}else{
		
	$("#shop-cart-num").html("购物车0件");
	$("#cart-num").html("(0/30)")
}

